import Vue from 'vue'
import Resource from 'vue-resource'
import NProgress from 'vue-nprogress'
import {
  sync
} from 'vuex-router-sync'
import App from './App.vue'
import router from './router'
import store from './store'
import * as filters from './filters'
import {
  TOGGLE_SIDEBAR
} from 'vuex-store/mutation-types'
Vue.use(Resource)
Vue.use(NProgress)

// Vue.prototype.$electron = require('electron')
// const vueAuth = require('@websanova/vue-auth')
// const vueAuthResolvers = {
//   auth: require('@websanova/vue-auth/drivers/auth/bearer.js'),
//   http: require('@websanova/vue-auth/drivers/http/vue-resource.1.x.js'),
//   router: require('@websanova/vue-auth/drivers/router/vue-router.2.x.js'),
//   rolesVar: 'roles'
// }

// Vue.use(vueAuth, vueAuthResolvers)
// Enable devtools
Vue.config.devtools = true

sync(store, router)

const nprogress = new NProgress({
  parent: '.nprogress-container'
})

const {
  state
} = store

router.beforeEach((route, redirect, next) => {
  if (state.app.device.isMobile && state.app.sidebar.opened) {
    store.commit(TOGGLE_SIDEBAR, false)
  }
  next()
})

Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

const app = new Vue({
  router,
  store,
  nprogress,
  ...App
})

export {
  app,
  router,
  store
}
